package SGEngine2

import (
//"fmt"
)

//BetterArray/////////////////////////////////
type Array struct {
	buffers []interface{}
	size    int
}

func (a *Array) Count() int {
	return a.size
}

func (b *Array) Get(index int) interface{} {
	return b.buffers[index]
}

func (b *Array) Set(index int, data interface{}) {
	b.buffers[index] = data
}

func (b *Array) Add(data interface{}) {

	if b.buffers == nil || b.size == cap(b.buffers) {
		//fmt.Println("Am")
		b.AllocateMore()
	}
	b.buffers[b.size] = data
	b.size++
}

func (b *Array) AllocateMore() {
	if b.buffers == nil {
		b.buffers = make([]interface{}, 8)
	} else {
		bflen := len(b.buffers)
		if bflen >= 8 {
			newbuffer := make([]interface{}, bflen<<1)
			copy(newbuffer, b.buffers)
			b.buffers = newbuffer
		}
	}
}

func (b *Array) Clear() {
	b.size = 0
}

func (b *Array) Release() {
	b.size = 0
	b.buffers = nil
}

func (b *Array) RemoveAt(index int) {
	if b.buffers != nil && index < len(b.buffers) {

		for i := index; i < b.size; i++ {
			b.buffers[i] = b.buffers[i+1]
			b.buffers[b.size] = nil
		}
		b.size = b.size - 1
	}
}

func (b *Array) Remove(data interface{}) {
	for i := 0; i < b.size; i++ {
		if data == b.buffers[i] {
			b.RemoveAt(i)
		}
	}
}

func (b *Array) Each(F func(interface{})) {
	for i := 0; i < b.size; i++ {
		F(b.buffers[i])
	}
}

//Array////////////////////////////////////////////////////////

///Rect///////////////////////////////////////////////////////////
type Rect struct {
	MinX float64
	MinY float64
	MaxX float64
	MaxY float64
}
type Bounds struct {
	Max    Vec3
	Min    Vec3
	Center Vec3
	Size   Vec3
}
type QuadRect struct {
	Top    float32
	Left   float32
	Right  float32
	Bottom float32
}
